﻿using Cls_BoticasySaludBE;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cls_BoticasySaludDA
{
    public class CategoriaDA
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnx"].ConnectionString);
        public List<Categoria> GetListarCategoriaDA()
        {
            List<Categoria> ListaCategorias = new List<Categoria>();
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.CommandText = "Sp_ListarCategoria";
                cn.Open();
                IDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    Categoria Categorias = new Categoria();
                    Categorias.CodCategoria = dr.GetInt32(0);
                    Categorias.Descripcion = dr.GetString(1);
                    ListaCategorias.Add(Categorias);
                }
                return ListaCategorias;
            }
            catch (SqlException ex)
            {
                return null;
            }

        }
    }
}
